#ifndef WIDGET_HUMAN_H
#define WIDGET_HUMAN_H



#include "units.h"
#include "gui.h"
#include "game.h"
#include <QtGui>
#include <QObject>
#include <vector>



class unit;

class pre_buy_info;
class pre_sell_info;



//! @brief Class representating normal game square in human widget
class map_square_buy: public QGraphicsPixmapItem
{

public:

	/** @brief Constructor does only default stuff
	*	@param parent Qt parent
	*	@param scene Qt scene, where the pixmap is
	*/
	map_square_buy( QGraphicsItem* parent = 0, QGraphicsScene* scene = 0 );

};



//! @brief Class representating bonus in human widget
class map_bonus_buy: public QGraphicsPixmapItem
{

public:

	/** @brief Constructor loads proper pixmap for the bonus
	*	@param b bonus represented by the pixmap, constraint: b != 0
	*	@param parent Qt parent
	*	@param scene Qt scene, where the pixmap is
	*/
	map_bonus_buy( bonus* b, QGraphicsItem* parent = 0, QGraphicsScene* scene = 0 );


private:

	//! bonus represented by the pixmap
	bonus* bon;

};



//! @brief Class representating square, where units can be placed in human widget
class map_units_square: public QGraphicsPixmapItem
{

public:

	/** @brief Constructor loads proper pixmap for the square
	*	@param id id of the player, who can place units there, constraint: id < "MAX_PL"
	*	@param parent Qt parent
	*	@param scene Qt scene, where the pixmap is
	*/
	map_units_square( unsigned int id, QGraphicsItem* parent = 0, QGraphicsScene* scene = 0 );


protected:

	/**	@brief Qt mouse press event
	*	right click	-> not defined
	*	left click	-> place bouhgt unit there
	*	@param event for resolving pressed button
	*/
	void mousePressEvent( QGraphicsSceneMouseEvent* event );

};



//! @brief Class representating bought unit in human widget
class map_unit_buy: public QGraphicsPixmapItem
{

public:
	
	/** @brief Constructor loads proper pixmap for the unit
	*	@param un bought unit, constraint: un != 0
	*	@param parent Qt parent
	*	@param scene Qt scene, where the pixmap is
	*/
	map_unit_buy( unit* un, QGraphicsItem* parent = 0, QGraphicsScene* scene = 0 );

	/**	@brief Sets unit's info - for destruction purposes
	*	@param ui info label to be set
	*/
	void setUnitInfo( QLabel* ui )
	{
		uinfo = ui;
	};

	//! bought unit
	unit* u;
	//! bought unit's info
	QLabel* uinfo;

protected:

	/**	@brief Qt mouse press event
	*	right click	-> sell bought unit
	*	left click	-> not defined
	*	@param event for resolving pressed button
	*/
	void mousePressEvent( QGraphicsSceneMouseEvent* event );

};



//! @brief Class representating one unit from units prototypes
class unit_buy: public QWidget
{

	Q_OBJECT

public:


	/** @brief Constructor creates line with information (all parameters) and buy button
	*	@param un unit, that is represented by the line, constraint: un != 0
	*	@param parent Qt parent
	*	@param flags Qt flags
	*/
	unit_buy( unit* un, QWidget* parent = 0, Qt::WindowFlags flags = 0 );

	//! button for buying the unit
	QPushButton* buy_b;

	//! unit, that is representaed by the line
	unit* u;


private slots:

	//! @brief Qt slot that buys this unit
	void buy_unit();

};



//! @brief Gui class for buying units of local player
class human_widget: public QWidget
{
	
	Q_OBJECT

public:

	/** @brief Creates part of the gui
	*	@param pl local player, for whom are the units being bought, constraint: pl != 0
	*	@param nb button NEXT, constraint: nb != 0
	*	@param parent Qt parent
	*	@param flags Qt flags
	*/
	human_widget( player* pl, QPushButton* nb, QWidget* parent = 0, Qt::WindowFlags flags = 0 );

	/** @brief Forwards command to main engine
	*	@param plr player, that sends the command
	*	@param cmd sent command
	*/
	void forward_command( player* plr, std::string cmd )
	{
		emit send_command( plr, cmd );
	};

	//! @brief Creates the map with all squares
	void create_map();
	//! @brief Sets laber showing money left
	void set_label_money();
	/**	@brief	Prints bought unit's information
	*	@param	bu bought unit, constraint: bu != 0
	*	@return generated label with information
	*/
	QLabel* print_bought_unit( unit* bu );

	//! @brief Places all loaded objects to the map
	void set_loaded_objects();

	/** @brief Shows sell event in gui
	*	@param u unit to sell
	*	@param psi some aditional information needed for visualising the event
	*/
	void show_sell( unit* u, pre_sell_info* psi );
	/** @brief Shows buy event in gui
	*	@param u moving unit
	*	@param x x coordinate, where it moves, constraint: x < map->size_x
	*	@param y y coordinate, where it moves, constraint: y < map->size_y
	*	@param pbi some aditional information needed for visualising the event
	*/
	void show_buy( unit* u, unsigned int x, unsigned int y, pre_buy_info* pbi );

	
	//! player, for whom is the widget created
	player* current_player;
	//! list of bought units
	QWidget* bought_units_w;
	//! map
	QGraphicsScene* gs;

	//! money left label
	QLabel* money_l;
	//! button NEXT
	QPushButton* next_b;

	//! vector of units in shop
	std::vector< unit_buy* > units_buy_array;

	//! 2D array of terrain map
	array2d< map_square_buy* >* map_array;
	//! bought, but not already placed unit
	int bought_unit;


signals:

	//! @brief Qt singnal that sends commands to game core
	void send_command( player*, std::string );

};







#endif